package com.yukh.framework.iso8583;

import java.io.UnsupportedEncodingException;

import org.jpos.iso.Interpreter;

public class Zh_CN_Interpreter implements Interpreter {
	public static final Zh_CN_Interpreter INSTANCE = new Zh_CN_Interpreter();

	public int getPackedLength(int nDataUnits) {
		return nDataUnits;
	}

	public void interpret(String data, byte[] b, int offset) {
		try {
			byte[] raw = data.getBytes("GBK");
			System.arraycopy(raw, 0, b, offset, b.length);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
	}

	public String uninterpret(byte[] rawData, int offset, int length) {
		try {
			return new String(rawData, offset, length, "GBK");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return null;
	}
}
